import { Vector2D } from '../utils/Vector2D';

type FoodType = 'energy' | 'poison' | 'magnet';

export class Food {
    private position: Vector2D;
    private type: FoodType;
    private value: number;
    private size: number;
    private color: string;
    private pulseEffect: boolean;

    constructor(position: Vector2D) {
        this.position = position;
        this.type = this.generateType();
        this.value = this.calculateValue();
        this.initializeVisuals();
    }

    private initializeVisuals(): void {
        switch (this.type) {
            case 'energy':
                this.size = 15;
                this.color = '#FFD700';
                this.pulseEffect = false;
                break;
            case 'poison':
                this.size = 20;
                this.color = '#FF0000';
                this.pulseEffect = true;
                break;
            case 'magnet':
                this.size = 25;
                this.color = '#8A2BE2';
                this.pulseEffect = true;
                break;
        }
    }

    private generateType(): FoodType {
        const random = Math.random();
        if (random < 0.6) {
            return 'energy';
        } else if (random < 0.9) {
            return 'magnet';
        } else {
            return 'poison';
        }
    }

    private calculateValue(): number {
        switch (this.type) {
            case 'energy':
                return 10;
            case 'poison':
                return -5;
            case 'magnet':
                return 15;
            default:
                return 0;
        }
    }

    public getPosition(): Vector2D {
        return this.position;
    }

    public getType(): FoodType {
        return this.type;
    }

    public getValue(): number {
        return this.value;
    }

    public getSize(): number {
        return this.size;
    }

    public getColor(): string {
        return this.color;
    }

    public hasPulseEffect(): boolean {
        return this.pulseEffect;
    }

    public setPosition(newPosition: Vector2D): void {
        this.position = newPosition;
    }

    // 移除了复杂的碰撞检测逻辑，由CollisionSystem统一处理
    // 保留简单的点对点距离检测方法供CollisionSystem使用
    public getDistanceTo(point: Vector2D): number {
        return this.position.distance(point);
    }
}